﻿namespace WMS6.Web.Configuration
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoDetailServiceRef;

    public class AreaDetail : BasePage
    {
        protected Button btnCancel;
        protected Button btnSave;
        protected HtmlForm F2163;
        protected HtmlInputHidden hdnFrom;
        protected Label lblAreaDetail;
        protected Label lblAreaID;
        protected Label lblMsg;
        protected Label lblSeqNo;
        protected Label lblZoneID;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtAreaID;
        protected TextBox txtSeqNo;
        protected TextBox txtZoneID;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Server.Transfer(string.Format("Area.aspx?from={0}&detail={1}&ID={2}", this.hdnFrom.Value, "1", base.Server.UrlEncode(this.txtAreaID.Text.Trim())));
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtZoneID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2340_004");
            }
            else
            {
                bool success = false;
                try
                {
                    AreaDetailInfo areaDetail = new AreaDetailInfo {
                        AreaID = this.txtAreaID.Text.Trim(),
                        SeqNo = int.Parse(this.txtSeqNo.Text.Trim()),
                        ZoneID = this.txtZoneID.Text.Trim(),
                        CreatedBy = base.UserInfo.UserID
                    };
                    if (!string.IsNullOrEmpty(BaseInfoDetailServiceClientProxy.GetInstance().InsertDetail(areaDetail, "AREA_DETAIL")))
                    {
                        success = true;
                    }
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F2340_005") + ex.Message;
                    return;
                }
                if (success)
                {
                    base.Response.Redirect(string.Format("Area.aspx?from={0}&detail={1}&ID={2}", this.hdnFrom.Value, "1", base.Server.UrlEncode(this.txtAreaID.Text.Trim())));
                }
            }
        }

        private void LoadData()
        {
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"].ToString()))
            {
                string from = base.Request.QueryString["from"].ToString();
                this.hdnFrom.Value = from;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"].ToString()))
            {
                string areaID = base.Request.QueryString["ID"].ToString();
                this.txtAreaID.Text = areaID;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["SeqNO"].ToString()))
            {
                string seqNo = base.Request.QueryString["SeqNO"].ToString();
                this.txtSeqNo.Text = seqNo;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }
    }
}

